/**
 * 
 */
package com.effectiv.gooruda.rest.api.service;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;

import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Dhrubo
 *
 */
@Component
public class BrokerViewMBeanFactoryBean implements FactoryBean<BrokerViewMBean> {
	
	@Autowired
	private MBeanServerConnection mBeanServerConnection;

	@Override
	public BrokerViewMBean getObject() throws Exception {
		ObjectName jmxBrokerName = new ObjectName("org.apache.activemq:BrokerName=amq-broker,Type=Broker");
		BrokerViewMBean brokerView =
	            MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, jmxBrokerName, BrokerViewMBean.class, true);
		return brokerView;
	}

	@Override
	public Class<BrokerViewMBean> getObjectType() {
		
		return BrokerViewMBean.class;
	}

	@Override
	public boolean isSingleton() {
		
		return true;
	}

}
